/******************************************************************************
This .do file produces the results for Figures OB5 & OB6. 
The figures were produced in R using estimated saved from these analyses. 
******************************************************************************/

clear
use "ess_cleaned_whole.dta"
set more off

*Restrict to citizens
keep if citizen == 1

/*********************************
Weights
*********************************/

gen anweight = pspwght*pweight
label var anweight "Analysis Weight"
*Note: svyset is not used because mixed does not work with svy: in this version of Stata. 

/*********************************
Labelling
*********************************/

label var self_te "Self Transcendence vs. Self-Enhancement"
label var cons_open1 "Conservation vs. Openness"
label var age "Age"
label var gender "Gender"
label def gend 1 "Female" 0 "Male"
label values gender gend

recode born_when (1=1 "Born in Country") (2 3 4 = 2 "Came to Country <20 Yrs Ago") (5 = 3 "Came to Country 20+ Yrs Ago"), gen(born_when1)
label var born_when1 "Born in Country?"

recode minority (0=1 "Minority Group") (1=0 "Non-Minority"), gen(minority1)
label var minority1 "Member of Minority?"

recode edulvla (55=.)
label var edulvla "Own Education"
label def ed 0 "Other Ed Level"  1 "< Lower Secondary" 2 "Lower Secondary" 3 "Upper Secondary" 4 "Post-Secondary, Non-Tertiary" 5 "Tertiary Education"
label values edulvla ed

recode edulvlfa (55=.)
label var edulvlfa "Father's Education"
label val edulvlfa ed

recode union (1 = 0 "Never a Union Member") (2 3 = 1 "Currently/Previously in Union"), gen(union1)
label var union1 "Union Membership"

label var socialtrust "Interpersonal Trust"
label var sclmeet "Freq of Social Interactions"
label var religiosity "Religiosity"
label var yrlvdae "Residential Stability"

label def dom 1 "Big City" 2 "Suburbs" 3 "Small City" 4 "Country Village" 5 "Countryside" 
label values domicil dom

label var post_soviet "Socialist Country?"
label def pos 1 "Socialist Country" 0 "Non-Socialist Country"
label values post_soviet pos

label var demyrs_01 "Years of Democracy"
label var ethnic_01 "Ethnic Heterogeneity"


/*********************************
Rescaling Continuous Variables to 0-1 Scale
*********************************/

foreach var in support_others vote_elections obey opinions volunteer beactive self_te cons_open1 age socialtrust sclmeet religiosity yrlvdae {
	summ `var'
	replace `var' = (`var' - r(min))/(r(max)-r(min))
}


/*********************************
Models, Table, Saved Results
*********************************/

eststo clear
foreach var in vote_elections obey support_others opinions volunteer beactive  {
	eststo: mixed `var' age i.gender i.minority1 i.union1 i.edulvla ib1.edulvlfa i.born_when1 i.post_soviet demyrs_01 ethnic_01 [pweight=anweight] || country: ,  stddev
		parmest, label format(estimate min95 max95 p) list(parm label estimate min95 max95 p) saving(`var'2_justdem.dta, replace)
	}
esttab using justdem.rtf, replace label se b(2) aic bic onecell transform(ln*: exp(@) exp(@)) ///
		addnote("Models use survey weights. Value orientation slopes are allowed to vary across countries. All continuous variables are scaled to range from 0-1.") ///
		mtitles("Vote" "Obey" "Support" "Opinions" "Volunteer" "Be Active") ///
		title("{\b Table X}: Demographics and Norms") 
	
	
	
	
	
	
	
	
	


